{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding: UTF-8 -*-\n",
    "import numpy as np\n",
    "import pandas as pd \n",
    "import operator\n",
    "import os\n",
    "import random\n",
    "from os import listdir\n",
    "from sklearn.svm import SVC\n",
    "import joblib\n",
    "from shutil import copyfile\n",
    "from os import getcwd\n",
    "from os import listdir\n",
    "\n",
    "def img2vector(filename):\n",
    "    \"\"\"\n",
    "    Parameters:\n",
    "        filename - 文件名\n",
    "    Returns:\n",
    "        returnVect - 返回的二进制图像的1x29774向量\n",
    "    \"\"\"\n",
    "    fr =  pd.read_csv(filename,header=0,index_col=False,sep = ',')#从0行开始算，重新设置一列成为index值\n",
    "    returnVect=np.array(fr['feature']).reshape(1,29774 )#转换为矩阵\n",
    "    return returnVect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "样本总数: 169\n",
      "患病样本比例: 44.37869822485207%, 患病样本数: 75\n",
      "健康样本比例: 55.62130177514793%, 健康样本数: 94\n",
      "训练集中患病样本数: 7\n",
      "测试集中患病样本数: 68\n",
      "训练集中健康样本数: 9\n",
      "测试集中健康样本数: 85\n"
     ]
    }
   ],
   "source": [
    "#数据总览\n",
    "def data_summary(main_path):\n",
    "    \n",
    "    yes_path = main_path+'AD'\n",
    "    no_path = main_path+'HC'\n",
    "        \n",
    "    # number of files (images) that are in the the folder named 'yes' that represent tumorous (positive) examples\n",
    "    m_pos = len(listdir(yes_path))\n",
    "    # number of files (images) that are in the the folder named 'no' that represent non-tumorous (negative) examples\n",
    "    m_neg = len(listdir(no_path))\n",
    "    # number of all examples\n",
    "    m = (m_pos+m_neg)\n",
    "    \n",
    "    pos_prec = (m_pos* 100.0)/ m\n",
    "    neg_prec = (m_neg* 100.0)/ m\n",
    "    \n",
    "    print(f\"样本总数: {m}\")\n",
    "    print(f\"患病样本比例: {pos_prec}%, 患病样本数: {m_pos}\") \n",
    "    print(f\"健康样本比例: {neg_prec}%, 健康样本数: {m_neg}\") \n",
    "    \n",
    "augmented_data_path = 'fix-csv-data/'    \n",
    "data_summary(augmented_data_path)\n",
    "\n",
    "\n",
    "#将数据集按比例划分为训练集和测试集\n",
    "def split_data(SOURCE, TRAINING, TESTING, SPLIT_SIZE):\n",
    "    dataset = []\n",
    "    \n",
    "    for unitData in os.listdir(SOURCE):\n",
    "        data = SOURCE + unitData\n",
    "        if(os.path.getsize(data) > 0):\n",
    "            dataset.append(unitData)\n",
    "        else:\n",
    "            print('Skipped ' + unitData)\n",
    "            print('Invalid file i.e zero size')\n",
    "    \n",
    "    train_set_length = int(len(dataset) * SPLIT_SIZE)\n",
    "    test_set_length = int(len(dataset) - train_set_length)\n",
    "    np.random.shuffle(dataset) ##打乱文件列表\n",
    "    train_set = dataset[0:train_set_length]\n",
    "    test_set = dataset[-test_set_length:]\n",
    "       \n",
    "    for unitData in train_set:\n",
    "        temp_train_set = SOURCE + unitData\n",
    "        final_train_set = TRAINING + unitData\n",
    "        copyfile(temp_train_set, final_train_set)\n",
    "    \n",
    "    for unitData in test_set:\n",
    "        temp_test_set = SOURCE + unitData\n",
    "        final_test_set = TESTING + unitData\n",
    "        copyfile(temp_test_set, final_test_set)\n",
    "        \n",
    "        \n",
    "YES_SOURCE_DIR = \"fix-csv-data/AD/\"\n",
    "TRAINING_YES_DIR = \"fix-csv-data/train_ad/\"\n",
    "TESTING_YES_DIR = \"fix-csv-data/test_ad/\"\n",
    "NO_SOURCE_DIR = \"fix-csv-data/HC/\"\n",
    "TRAINING_NO_DIR = \"fix-csv-data/train_hc/\"\n",
    "TESTING_NO_DIR = \"fix-csv-data/test_hc/\"\n",
    "split_size = .1\n",
    "split_data(YES_SOURCE_DIR, TRAINING_YES_DIR, TESTING_YES_DIR, split_size)\n",
    "split_data(NO_SOURCE_DIR, TRAINING_NO_DIR, TESTING_NO_DIR, split_size)\n",
    "print(\"训练集中患病样本数:\", len(os.listdir('fix-csv-data/train_ad/')))\n",
    "print(\"测试集中患病样本数:\", len(os.listdir('fix-csv-data/test_ad/')))\n",
    "print(\"训练集中健康样本数:\", len(os.listdir('fix-csv-data/train_hc/')))\n",
    "print(\"测试集中健康样本数:\", len(os.listdir('fix-csv-data/test_hc/')))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 基因样本分类测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SVC(C=200, kernel='sigmoid')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#测试集的Lab\n",
    "hwLabels = []\n",
    "#返回train目录下的文件名\n",
    "train_ad_FileList = listdir('fix-csv-data/train_ad')\n",
    "train_hc_FileList = listdir('fix-csv-data/train_hc')\n",
    "#返回ad文件夹下文件的个数\n",
    "m = len(train_ad_FileList)\n",
    "#返回ad文件夹下文件的个数\n",
    "n = len(train_hc_FileList)\n",
    "#初始化训练的Mat矩阵,测试集\n",
    "trainingMat = np.zeros((m+n, 29774))\n",
    "#解析出训练集的类别\n",
    "for i in range(m):\n",
    "    #获得分类的数字\n",
    "    classNumber = int(0)\n",
    "    #获取文件名\n",
    "    fileNameStr = train_ad_FileList[i]\n",
    "    #将获得的类别添加到hwLabels中\n",
    "    hwLabels.append(classNumber)\n",
    "    #将每一个文件的1x29774数据存储到trainingMat矩阵中\n",
    "    trainingMat[i,:] = img2vector('fix-csv-data/train_ad/%s' % (fileNameStr))\n",
    "\n",
    "#解析出训练集的类别\n",
    "for i in range(n):\n",
    "    #获得分类的数字\n",
    "    classNumber = int(1)\n",
    "    #获取文件名\n",
    "    fileNameStr = train_hc_FileList[i]\n",
    "    #将获得的类别添加到hwLabels中\n",
    "    hwLabels.append(classNumber)\n",
    "    #将每一个文件的1x29774数据存储到trainingMat矩阵中\n",
    "    trainingMat[i+m,:] = img2vector('fix-csv-data/train_hc/%s' % (fileNameStr))\n",
    "    \n",
    "clf = SVC(C=200,kernel='sigmoid')\n",
    "clf.fit(trainingMat,hwLabels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['svm-model.m']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#保存模型\n",
    "joblib.dump(clf, 'svm-model.m')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#读取模型\n",
    "clf = joblib.load('svm-model.m')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "文件名为009_S_5252.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为011_S_4827.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为011_S_4845.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为011_S_4906.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为011_S_4949.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为013_S_5071.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为014_S_4039.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为018_S_4733.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为018_S_5240.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为019_S_4252.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为019_S_4477.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为019_S_5012.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为019_S_5019.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为023_S_5120.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为023_S_5241.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为024_S_4223.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为024_S_4280.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为024_S_4905.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为024_S_5054.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为031_S_4024.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为033_S_5013.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为033_S_5017.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为033_S_5087.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为036_S_4820.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为036_S_4894.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为036_S_5063.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为036_S_5112.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为036_S_5210.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为037_S_4770.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为037_S_4879.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为037_S_5162.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为053_S_5070.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为053_S_5208.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为067_S_4728.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为067_S_5205.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为070_S_4719.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为072_S_4769.csv\t分类返回结果为1\t真实结果为0\n",
      "文件名为073_S_5016.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为073_S_5090.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为100_S_5106.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为116_S_4195.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为116_S_4209.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为116_S_4338.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为116_S_4732.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为123_S_4526.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为128_S_4772.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为128_S_4774.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为128_S_4792.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为128_S_5123.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_4730.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_4971.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_4982.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_4984.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_4990.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_4997.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_5006.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_5059.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为130_S_5231.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为131_S_5138.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为135_S_4863.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为135_S_4954.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为135_S_5015.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为135_S_5275.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为136_S_4993.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为137_S_4211.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为137_S_4258.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为137_S_4756.csv\t分类返回结果为0\t真实结果为0\n",
      "文件名为153_S_4172.csv\t分类返回结果为0\t真实结果为0\n",
      "总共错了1个数据\n",
      "错误率为1.470588%\n"
     ]
    }
   ],
   "source": [
    "#返回test目录下的文件列表\n",
    "testFileList = listdir('fix-csv-data/test_ad')\n",
    "#错误检测计数\n",
    "errorCount = 0.0\n",
    "#测试数据的数量\n",
    "mTest = len(testFileList)\n",
    "#从文件中解析出测试集的类别并进行分类测试\n",
    "for i in range(mTest):\n",
    "    #获得文件的名字\n",
    "    fileNameStr = testFileList[i]\n",
    "    #获得分类的数字\n",
    "    classNumber = int(0)\n",
    "    #获得测试集的1x29929向量,用于训练\n",
    "    vectorUnderTest = img2vector('fix-csv-data/test_ad/%s' % (fileNameStr))\n",
    "    #获得预测结果\n",
    "    # classifierResult = classify0(vectorUnderTest, trainingMat, hwLabels, 3)\n",
    "    classifierResult = clf.predict(vectorUnderTest)\n",
    "    print(\"文件名为%s\\t分类返回结果为%d\\t真实结果为%d\" % (fileNameStr,classifierResult, classNumber))\n",
    "    if(classifierResult != classNumber):\n",
    "        errorCount += 1.0\n",
    "print(\"总共错了%d个数据\\n错误率为%f%%\" % (errorCount, errorCount/mTest * 100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "文件名为007_S_4488.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为007_S_4516.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为009_S_4337.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为009_S_4388.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为011_S_4075.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为011_S_4105.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为011_S_4120.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为011_S_4222.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为011_S_4278.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为012_S_4026.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为013_S_4616.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为014_S_4080.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为014_S_4093.csv\t分类返回结果为0\t真实结果为1\n",
      "文件名为014_S_4401.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为016_S_4121.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为016_S_4951.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为016_S_4952.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为018_S_4257.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为018_S_4313.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为018_S_4349.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为018_S_4399.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为018_S_4400.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为019_S_4367.csv\t分类返回结果为0\t真实结果为1\n",
      "文件名为019_S_4835.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为023_S_4020.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为023_S_4164.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为023_S_4448.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为024_S_4084.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为024_S_4158.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为031_S_4021.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为031_S_4032.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为031_S_4218.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为031_S_4474.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为031_S_4496.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为033_S_4176.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为033_S_4177.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为033_S_4179.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为033_S_4505.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为033_S_4508.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为036_S_4389.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为036_S_4491.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为036_S_4878.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为037_S_4028.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为037_S_4071.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为037_S_4308.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为037_S_4410.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为070_S_4856.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为070_S_5040.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为073_S_4155.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为073_S_4382.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为073_S_4393.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为073_S_4739.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为073_S_4762.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为073_S_4795.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为073_S_5023.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为094_S_4234.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为116_S_4010.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为116_S_4043.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为116_S_4092.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为116_S_4453.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为116_S_4483.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为116_S_4855.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为128_S_4586.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为128_S_4832.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为129_S_4369.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为129_S_4371.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为129_S_4396.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为129_S_4422.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为130_S_4343.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为130_S_4352.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为135_S_4446.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为136_S_4269.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为137_S_4466.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为137_S_4587.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为137_S_4632.csv\t分类返回结果为0\t真实结果为1\n",
      "文件名为153_S_4125.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为153_S_4139.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为153_S_4151.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为153_S_4372.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为941_S_4066.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为941_S_4100.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为941_S_4255.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为941_S_4292.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为941_S_4365.csv\t分类返回结果为1\t真实结果为1\n",
      "文件名为941_S_4376.csv\t分类返回结果为1\t真实结果为1\n",
      "总共错了3个数据\n",
      "错误率为3.529412%\n"
     ]
    }
   ],
   "source": [
    "#返回test目录下的文件列表\n",
    "testFileList = listdir('fix-csv-data/test_hc')\n",
    "#错误检测计数\n",
    "errorCount = 0.0\n",
    "#测试数据的数量\n",
    "mTest = len(testFileList)\n",
    "#从文件中解析出测试集的类别并进行分类测试\n",
    "for i in range(mTest):\n",
    "    #获得文件的名字\n",
    "    fileNameStr = testFileList[i]\n",
    "    #获得分类的数字\n",
    "    classNumber = int(1)\n",
    "    #获得测试集的1x29929向量,用于训练\n",
    "    vectorUnderTest = img2vector('fix-csv-data/test_hc/%s' % (fileNameStr))\n",
    "    #获得预测结果\n",
    "    # classifierResult = classify0(vectorUnderTest, trainingMat, hwLabels, 3)\n",
    "    classifierResult = clf.predict(vectorUnderTest)\n",
    "    print(\"文件名为%s\\t分类返回结果为%d\\t真实结果为%d\" % (fileNameStr,classifierResult, classNumber))\n",
    "    if(classifierResult != classNumber):\n",
    "        errorCount += 1.0\n",
    "print(\"总共错了%d个数据\\n错误率为%f%%\" % (errorCount, errorCount/mTest * 100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(16, 29774)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trainingMat.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[112.,  16., 112., ...,  64., 255., 128.],\n",
       "       [112.,  16., 176., ..., 255., 255., 255.],\n",
       "       [112.,  64., 112., ...,  64., 255., 255.],\n",
       "       ...,\n",
       "       [ 96.,  16., 176., ...,  16., 255., 255.],\n",
       "       [176.,  16., 112., ...,  16., 255., 255.],\n",
       "       [112.,  16., 112., ...,  16.,  64., 128.]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trainingMat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hwLabels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
